package hng.mapper;

import hng.model.ProductImgDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author 告白
 * @since 2024-07-02
 */
public interface ProductImgMapper extends BaseMapper<ProductImgDO> {

    /**
     * 通过商品id查找图片列表
     * @param productId
     * @return
     */
    @Select("SELECT img_url FROM product_img WHERE product_id = #{productId} ORDER BY weight ASC, id ASC")
    List<String> selectImgUrlsByProductId(@Param("productId") Integer productId);

    @Delete({
            "<script>",
            "DELETE FROM product_img ",
            "WHERE product_id IN ",
            "<foreach item='id' collection='idList' open='(' separator=',' close=')'> ",
            "#{id} ",
            "</foreach> ",
            "</script>"
    })
    void deleteByProductIds(@Param("idList") List<Integer> idList);
}
